﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using PWMIS.DataMap.Entity;

namespace MBServices
{
    // 注意: 如果更改此处的类名 "MBService"，也必须更新 Web.config 中对 "MBService" 的引用。
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class MBService : IMBService
    {
        public void DoWork()
        {
        }

        #region IMBService 成员

        [WebGet(BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json)]
        public List<MBModel.MB_User> GetMBUserList()
        {
            MBModel.MB_User curUserList = new MBModel.MB_User();
           // OQL query = new OQL(curUserList);
            OQL query = OQL.From (curUserList);
            query.Select();

            List<MBModel.MB_User> curlist = EntityQuery<MBModel.MB_User>.QueryList(query);
            //List<NBFModel.MB_User> curlist = new List<NBFModel.MB_User>();
            //NBFModel.MB_User item = new NBFModel.MB_User();
            //curlist.Add(item);
            return curlist;
     
       
        }

        //[WebGet(BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json)]
        //public List<NBFModel.Model_FoundMarket> GetFoundMarket()
        //{


        //    List<NBFModel.Model_FoundMarket> list = new List<NBFModel.Model_FoundMarket>();
        //    NBFModel.Model_FoundMarket item = new NBFModel.Model_FoundMarket();
        //    item.BuyState = "aaaa";
        //    item.dayyield = Convert.ToDecimal(1.0000002);
        //    item.maxfsrq = DateTime.Now;//日期的默认值序列化将会出现问题。
        //    item.tzfg = "2222";
        //    item.ljjz = Convert.ToDecimal(22.333);
        //    list.Add(item);
        //    return list;
        //}

        #endregion

        #region IMBService 成员

        //复杂的参数类型，不能使用Get方式。
        //[WebGet(BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json)]
        [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, Method = "POST")]
        public List<MBModel.MB_User> GetMBUserList(Dictionary<string, string> p)
        {
            MBModel.MB_User curUserList = new MBModel.MB_User();
            // OQL query = new OQL(curUserList);
            OQL query = OQL.From(curUserList);


            if (p.ContainsKey("UserMobile"))
                query.Select().Where(query.Condition.AND(curUserList.Mobile, "=", p["UserMobile"]));
            if (p.ContainsKey("UserName"))
                query.Select().Where(query.Condition.AND(curUserList.UserName, " like ", "%" + p["UserName"] + "%"));
            if (p.ContainsKey("UserEmail"))
                query.Select().Where(query.Condition.AND(curUserList.Email, "=", p["UserEmail"]));

            if (p.ContainsKey("UserAge"))
            {
                if (p["UserAge"].Split('$').Length == 2)
                {
                    query.Select().Where(query.Condition.AND(curUserList.Age, ">=", p["UserAge"].Split('$')[0]));
                    query.Select().Where(query.Condition.AND(curUserList.Age, "<=", p["UserAge"].Split('$')[1]));
                }
            }


            if (query.Condition.Parameters.Count==0)
                query.Select().Where(query.Condition.AND(curUserList.UID, "=","0"));
 
   



            //query.Select().Where(query.Condition.AND(curUserList.Mobile, " like ","%"+curUserList.Mobile+"%"));
            //query.Select().Where(query .Condition.AND (curUserList.Mobile,"=",curUserList.Mobile ));
            //query.Select().Where(query.Condition.AND(curUserList.UserName, "=", curUserList.UserName ));
            //query.Select().Where(query.Condition.AND(curUserList.Email, "=", curUserList.Email));

            List<MBModel.MB_User> curlist = EntityQuery<MBModel.MB_User>.QueryList(query);
            //List<NBFModel.MB_User> curlist = new List<NBFModel.MB_User>();
            //NBFModel.MB_User item = new NBFModel.MB_User();
            //curlist.Add(item);
            return curlist;
        }

        #endregion
    }
}
